/* Copyright (c) 2007 Easter
 * Author Yichao Zhang
 * Email Yichao.Zhang@gmail.com
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package ie.ucc.cs.anggao.finalproject.server.blogPost;

import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Properties;

import org.apache.xmlrpc.XmlRpcException;
import org.apache.xmlrpc.client.XmlRpcClient;
import org.apache.xmlrpc.client.XmlRpcClientConfigImpl;

public class WordpressClient {

	private String username = "";

	private String password = "";

	private String blogurl = "";

	public String getBlogurl() {
		return blogurl;
	}

	public void setBlogurl(String blogurl) {
		this.blogurl = blogurl;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public void post(HashMap content) throws Exception{
		XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();
		config.setServerURL(new URL(getBlogurl() + "/xmlrpc.php"));
		
		XmlRpcClient client = new XmlRpcClient();
		
		//Proxy
		Properties systemSettings = System.getProperties();
		systemSettings.put("http.proxyHost", "10.51.255.250");
		systemSettings.put("http.proxyPort", "8080");
		System.setProperties(systemSettings);
		
		client.setConfig(config);
		Object[] params = new Object[] { "1", getUsername(), getPassword(),content,
				true };
		
		try {
			client.execute("metaWeblog.newPost", params);
		} catch (XmlRpcException e) {
		
			e.printStackTrace();
		}
	}
	

}
